import axios from 'axios'

const baseURL = 'http://ludir.cn:8888/api/private/v1/'

axios.defaults.baseURL = baseURL

//导入进度条插件
import NProgress from 'nprogress'
//导入进度条样式
import 'nprogress/nprogress.css'


// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  NProgress.start()

  // 在发送请求之前做些什么
  let getToken= localStorage.getItem('tokenLogin') ||'';

 config.headers['Authorization']=getToken

  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});


axios.interceptors.response.use(function (response) {
  NProgress.done()
    // 2xx 范围内的状态码都会触发该函数。
    // 对响应数据做点什么
    // 取出localStorage中存储的token值

    return response.data;
  }, function (error) {
    // 超出 2xx 范围的状态码都会触发该函数。
    // 对响应错误做点什么
    return Promise.reject(error);
  });

export let checkLogin = (params)=>axios.post('login',params)

export let getUsers = (params)=>axios.get('users',params)

export let changeUserState = (params={})=>axios.put(`users/${params.uid}/state/${params.type}`)

export let addUsers = (params)=>axios.post('users',params)

export let delUsers = (id)=>axios.delete(`users/${id}`)

export let getUsersById = (id)=>axios.get(`users/${id}`)

export let editUsersById = (id, params)=>axios.put(`users/${id}`, params)

export let getRoleList=(params)=>axios.get(`roles`)

export let changeUserRole=(params)=> axios.put(`users/${params.id}/role`, {rid: params.rid})

export let getRightList = (params)=> axios.get(`rights/${params.type}`)

export let deleteRoleRight = (params)=> axios.delete(`roles/${params.roleId}/rights/${params.rightId}`)

export let grantRoleRight = (params)=> axios.post(`roles/${params.roleId}/rights`, {rids: params.rids})

export let addRole = (params)=> axios.post(`roles`,params)

export let editRole = (params)=> axios.put(`roles/${params.id}`, params)

export let deleteRoles = (params)=> axios.delete(`roles/${params.id}`)

export let getCategories = (params)=> axios.get('categories',{params: params})

export let addCategories = (params)=> axios.post(`categories`,params)

export let editCategories = (params)=> axios.put(`categories/${params.cat_id}`, {cat_name: params.cat_name})

export let deleteCategories = (params)=> axios.delete(`categories/${params.id}`)

export let getMenu = (params)=> axios.get('menus')

export let getParams = (params)=> axios.get(`categories/${params.cat_id}/attributes`,{params: params})

export let addParams = (params)=> axios.post(`categories/${params.cat_id}/attributes`,params)

export let editParams = (params)=> axios.put(`categories/${params.cat_id}/attributes/${params.attr_id}`, params)

export let deleteParams = (params)=> axios.delete(`categories/${params.cat_id}/attributes/${params.attr_id}`)


export let getReports = (params)=> axios.get('reports/type/1')


export let getGoods = (params)=> axios.get(`goods`,{params: params})

export let addGoods = (params)=> axios.post(`goods`,params)

export let editGoods = (params)=> axios.put(`goods/${params.goods_id}`, params)

export let deleteGoods = (params)=> axios.delete(`goods/${params.id}`)


export let getOrders = (params)=> axios.get(`orders`,{params: params})

export let editOrders = (params)=> axios.put(`orders/${params.order_id}`, params)

export let getKuaidi = (params)=> axios.get('kuaidi/110121212622')








